package com.zjt;

import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.LinkedList;
import java.util.List;


public class MyFileReader {
    /*
     * @path 文件路径
     *
     * @load() 提取文件中每一行的信息储存至向量，并返回向量
     */
    static public List<String> load(String path) {

        List<String> vec = new LinkedList<>();// 储存文件中每一行的信息

        LineNumberReader reader = null;
        FileReader in = null;

        try {
            in = new FileReader(path);
            reader = new LineNumberReader(in);
            while (true) {
                String str = reader.readLine();
                if (str == null)
                    break;
                vec.add(str);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null)
                    reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return vec;

    }
}
